//
//  AppDelegate.m
//  tabbar美团
//
//  Created by 小白 on 16/2/23.
//  Copyright © 2016年 小白. All rights reserved.
//

#import "AppDelegate.h"
#import "HomePAgeViewController.h"
#import "MerchantPageViewController.h"
#import "MinePageViewController.h"
#import "MusicPageViewController.h"
#import "OnsitePageViewController.h"


@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    //创建UITabBarItem
    //创建方式
   // [[UITabBarItem alloc]initWithTitle:@"title" image:[UIImage imageNamed:@"图片地址"] selectedImage:@"高亮图片"];
   // [[UITabBarItem alloc]initWithTitle:@"Title" image:[UIImage imageNamed:@"图片"] tag:0];
    //这里是选择系统默认的图片
   // [UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1
    HomePAgeViewController *homeVC = [[HomePAgeViewController alloc]init];
    MerchantPageViewController *mechantVC = [[MerchantPageViewController alloc]init];
    MinePageViewController *mineVC = [[MinePageViewController alloc]init];
    MusicPageViewController *musicVC = [[MusicPageViewController alloc]init];
    OnsitePageViewController *onsiteVC = [[OnsitePageViewController alloc]init];
    
    homeVC.title = @"主页";
    // 上面一句话相当于下面两句话
//    homeVC.tabBarItem.title = @"title";
//    homeVC.navigationItem.title = @"title";
    mechantVC.title = @"商铺";
    mineVC.title = @"我";
    musicVC.title = @"更多";
    onsiteVC.title = @"外卖";
    //右上角标
  //  UITabBarItem *item = [[UITabBarItem alloc]init];
   // item.badgeValue = @"8";
    UITabBarController *tabController = [[UITabBarController alloc]init];
    tabController.viewControllers = @[homeVC,mechantVC,onsiteVC,mineVC,musicVC];
    self.window.rootViewController = tabController;
    //将其ite的顺序打乱 其item的属性就会根据打乱的顺序排列
    //但是其文字信息是受 tabContriller里面子view的顺序排列的
//    UITabBarItem *itemHome = tabController.tabBar.items[2];
//    UITabBarItem *itemMenchant = tabController.tabBar.items[1];
//    UITabBarItem *itemMusic = tabController.tabBar.items[0];
//    UITabBarItem *itemMine = tabController.tabBar.items[3];
//    UITabBarItem *itemOnsite = tabController.tabBar.items[4];
    
    
    UITabBarItem *itemHome = tabController.tabBar.items[0];
    UITabBarItem *itemMenchant = tabController.tabBar.items[1];
    UITabBarItem *itemOnsite = tabController.tabBar.items[2];
    UITabBarItem *itemMine = tabController.tabBar.items[3];
    UITabBarItem *itemMusic = tabController.tabBar.items[4];

    
    //设置图片
    itemHome.image = [[UIImage imageNamed:@"icon_tabbar_homepage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    itemHome.selectedImage = [[UIImage imageNamed:@"icon_tabbar_homepage_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //设置位置
    //itemHome.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    itemMenchant.image = [[UIImage imageNamed:@"icon_tabbar_merchant_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    itemMenchant.selectedImage = [[UIImage imageNamed:@"icon_tabbar_merchant_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    itemOnsite.image = [[UIImage imageNamed:@"icon_tabbar_onsite"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    itemOnsite.selectedImage = [[UIImage imageNamed:@"icon_tabbar_onsite_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    itemMine.image = [[UIImage imageNamed:@"icon_tabbar_mine"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    itemMine.selectedImage = [[UIImage imageNamed:@"icon_tabbar_mine_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    itemMusic.image = [[UIImage imageNamed:@"icon_tabbar_misc"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    itemMusic.selectedImage = [[UIImage imageNamed:@"icon_tabbar_misc_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //设置tabbar字体的颜色
    tabController.tabBar.tintColor = [UIColor colorWithRed:0.0 green:0.687204 blue:0.614116 alpha:1];
    //右上角的角标
    itemHome.badgeValue = @"10";
    tabController.selectedIndex = 2;
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
